package com.le.tester.tip.generics;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.le.tester.javaThink.fourth.net.mindview.util.ConvertTo;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * createTime：2023/1/11 11:06
 * description：
 */
public class UseDemo {
    public static void main(String[] args) throws IllegalAccessException, IntrospectionException, InvocationTargetException {
        Boy boy = new Boy();
        boy.setName("AnSir");
        boy.setCode("001");
        boy.setUsedCar("honda");

        Girl girl = new Girl();
        girl.setName("Mari");
        girl.setCode("002");
        girl.setUsedPackage("LV");

        List<Boy> boyList = new ArrayList<>();
        List<Girl> girlList = new ArrayList<>();

        boyList.add(boy);
        girlList.add(girl);
        new UseDemo().get(boyList, Boy.class);
        new UseDemo().get(girlList, Girl.class);
    }

    public <T> Map<String, Object> get(List<T> source, Class<T> tClass) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
        Map<String, Object> map = null;
        try {
            map = new HashMap<>();
            System.out.println(tClass.getSimpleName());
            System.out.println(tClass.getName());
            System.out.println(tClass.getTypeName());
            Field[] declaredFields = tClass.getDeclaredFields();
            System.out.println(Arrays.toString(declaredFields));
        } catch (SecurityException e) {
            e.printStackTrace();
        }


        return map;
    }
}
